#pragma once
#include "refc_ptr.h"
#include "widget.h"
#include "window.h"

namespace krryn{
namespace gui{
	template<typename _RenderTag>
	class render_control : public widget{
	public:
		typedef core::refc_ptr<render_control> ptr;
		// no other typedefs because we're abstract

		void activate();
		void swap_buffers();
		virtual void* handle() = 0;
	};

	template<typename _RenderTag, typename _Parent>
	class render_control_initializer : public widget_initializer<_Parent>{
	public:
		render_control_initializer() 
			: m_Fullscreen(false), m_BitsPerPixel(32) {}

		render_control_initializer &parent(window::ptr a_Widget){
			m_Parent = a_Widget;
			return *this;
		}

		render_control_initializer &fullscreen(bool a_Fullscreen){
			m_Fullscreen = a_Fullscreen;
			return *this;
		}

		render_control_initializer &bits_per_pixel(unsigned int a_BitsPerPixel){
			m_BitsPerPixel = a_BitsPerPixel;
			return *this;
		}

		typename render_control<_RenderTag>::ptr create(){
			if(m_Parent.get() == 0){
				// create a default window if we have none
				m_Parent = 
					window::with()
						.width(m_Width)
						.top(m_Top)
						.left(m_Left)
						.height(m_Height)
					.create();

				// reset the top and left position because it doesn't make sense
				// to use it for both the window and this control
				m_Top = 0;
				m_Left = 0;
			}

			return typename render_control<_RenderTag>::ptr(
				new render_control<_RenderTag>(
					static_cast<_Parent&>(*this)));
		}

		unsigned int m_BitsPerPixel;
		window::ptr m_Parent;
		bool m_Fullscreen;
	};
}
}